<?php 
if ( ! function_exists('categoriasRecursivas')){
	
	function categoriasRecursivas($categorias, $separador = "", $nodeCategories = NULL){
		if($categorias){
	 		foreach($categorias as $categoria){
				$selected = "";			
				if($nodeCategories != NULL && isCategorySelected($categoria->id, $nodeCategories)){
					$selected = "selected='selected'";
				}
	 			?>
	 			<option value="<?php echo $categoria->id;?>" url="<?php echo $categoria->url_name;?>" <?php echo $selected;?>><?php echo "$separador |-- {$categoria->name}";?><?php if($categoria->visible == 0) echo " (no visible)"?></option> 
	 			<?php 
	 			if(isset($categoria->categories) && count($categoria->categories)>0){
	 				categoriasRecursivas($categoria->categories, $separador . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $nodeCategories);
	 			}
	 		}
		}
	}
}

if( ! function_exists('isCategorySelected')){
	function isCategorySelected($id, $categorias){
		if(isset($categorias)){
			foreach($categorias as $node_category){
				if($id == $node_category->id){
					return TRUE;
				}
			}	
		}
	
		return FALSE;
	}	
}
?>